package com.jl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jl.commons.result.PageDataInfo;
import com.jl.model.in.TitleIn;
import org.springframework.stereotype.Service;
import com.jl.model.Title;
import com.jl.mapper.TitleMapper;
import com.jl.service.ITitleService;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 维修职称表 服务实现类
 * </p>
 *
 * @author JiangJian
 * @since 2019-05-13
 */
@Service

public class TitleServiceImpl extends ServiceImpl<TitleMapper, Title> implements ITitleService {

    @Override
    public void selectTitleDataGrid(PageDataInfo<Map<String, Object>> pageDataInfo, QueryWrapper<Title> qw) {
        Page<Map<String, Object>> page = new Page<>();
        page.setSize(pageDataInfo.getSize());
        page.setCurrent(pageDataInfo.getCurrent());
        List<Map<String, Object>> mapList = baseMapper.selectDataGrid(page, qw);
        pageDataInfo.setTotal(page.getTotal());
        pageDataInfo.setRecords(mapList);
    }

    @Override
    public boolean isTitleNameUsed(String name, Long titleId) {
        TitleIn titleIn = baseMapper.selectTitleInByName(name);
        if(titleIn == null){
            //如果找不到数据则表示该数据没有被使用
            return true;
        }else{
            if(titleIn.getId().equals(titleId)){
                //如果这个数据就是他本身则可以使用
                return true;
            }
        }
        return false;
    }

}
